package com.mryang.hds.utils;

import com.mryang.hds.entity.PunchInfo;
import com.mryang.hds.entity.QuestionSolution;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Genius
 * @version 1.0.0
 * @ClassName PunchUtil.java
 * @Description TODO 打卡工具类
 * @createTime 2023年01月15日 22:50:00
 */
public class PunchUtil {

    // 将打卡问题字符串加工成QuestionSolution类的list集合
    public static List<PunchInfo> getQSList(String str, int uid,String time){

        // System.out.println(str);

        String[] split = str.split(";");
        // System.out.println(split.toString());

        List<PunchInfo> list = new ArrayList<>();

        // QuestionSolution punchInfo = new QuestionSolution();
        for (String s : split) {

            PunchInfo punchInfo = new PunchInfo();

            String[] select = s.split(",");

            StringBuilder piStr = new StringBuilder();
            if (select.length > 1){
                // String[] split1 = s.split(",");

                for (String s1 : select) {
                    String[] split2 = s1.split("-");
                    piStr.append(split2[1]).append(";");
                }
                punchInfo.setQuestionId(Integer.parseInt(s.split("-")[0]));
                punchInfo.setSolution(piStr.toString());
                punchInfo.setDataException(s.split("-")[2*select.length]);

            }else{
                String[] split1 = s.split("-");

                punchInfo.setQuestionId(Integer.parseInt(split1[0]));
                punchInfo.setSolution(split1[1]);
                punchInfo.setDataException(split1[2]);


            }
            punchInfo.setUserId(uid);
            punchInfo.setCreatTime(time);


            list.add(punchInfo);

        }

        // System.out.println(list.toString());

        return list;
    }
}
